<template>
  <div>
    <div>
      <el-input style="width: 800px" placeholder="请输入私钥" v-model="privateKey">
        <template slot="prepend">私钥：</template>
      </el-input>
      <el-button type="primary" @click="importAccountByPrivateKey">私钥导入账户</el-button>
    </div><br><br>

    <div>
      <el-input style="width: 800px" placeholder="请输入助记词" v-model="mnemonic">
        <template slot="prepend">助记词：</template>
      </el-input><br>
      <el-input style="width: 655px" placeholder="请输入符合bip44协议的账户path，例如： M/44H/60H/0H/0/ i" v-model="accountPath">
        <template slot="prepend">账户bip44地址：</template>
      </el-input>
      <el-button type="primary" @click="importAccountByMnemonic">助记词导入账户</el-button>
    </div><br><br>

    <div>
      <el-input style="width: 350px" placeholder="请输入密码" v-model="password">
        <template slot="prepend">密码：</template>
      </el-input>
      <el-button size="small" type="primary">选择keystore文件</el-button> |
      <el-button type="primary" @click="importAccountByKeystore">上传导入账户</el-button>
    </div>
    <div>
      <el-descriptions column=1 title="导入账户信息">
        <el-descriptions-item label="私钥">{{accountInfo.privateKey}}</el-descriptions-item>
        <el-descriptions-item label="公钥">{{accountInfo.publicKey}}</el-descriptions-item>
        <el-descriptions-item label="地址">{{accountInfo.address}}</el-descriptions-item>
        <el-descriptions-item label="账户地址">{{accountInfo.accountPath}}</el-descriptions-item>
      </el-descriptions>
    </div><br><br>

  </div>
</template>

<script>
export default {
  name: "importAccount",
  data() {
    return {
      privateKey: '',
      mnemonic: '',
      accountPath: 'M/44H/60H/0H/0/i',
      password: '',
      accountInfo: '',
    }
  },
  methods: {
    //点击更新按钮请求账户列表
    importAccountByPrivateKey() {
      //发送请求
      this.axios.post("/importAccountByPrivateKey",this.privateKey).then(res => {
        this.accountInfo = res.data;
      })
    },
    importAccountByMnemonic() {
      //发送请求
      this.axios.post("/importAccountByMnemonic",{
        mnemonic: this.mnemonic,
        accountPath: this.accountPath,
      }).then(res => {
        this.accountInfo = res.data;
      })
    },
    importAccountByKeystore() {
      //发送请求
      this.axios.post("/importAccountByKeystore",{
        mnemonic: this.mnemonic,
      }).then(res => {
        this.accountInfo = res.data;
      })
    },
  }
}



</script>

<style scoped>

</style>

